class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        rnHash = {}
        for i in ransomNote:
            rnHash.setdefault(i, 0)
            rnHash[i] += 1
        i = 0
        while i<len(magazine) and len(rnHash)>0:
            if magazine[i] in rnHash:
                rnHash[magazine[i]] -= 1
                if rnHash[magazine[i]] == 0:
                    rnHash.pop(magazine[i])
            i+=1
        return len(rnHash)==0


if __name__ == '__main__':
    so = Solution()
    s = "abgfc"
    t = "ahbgdc"
    r = so.canConstruct(s, t)
    print(r)
